/******************************************************************************
*
* This file is part of FreeTrack (http://code.google.com/p/qtfreetrack).
* BY Willy Gardiol (willy@gardiol.org)
*
* FreeTrack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FreeTrack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>
*
******************************************************************************/

#ifndef CONFIGFILE_H
#define CONFIGFILE_H

#include <QtCore>

class ConfigFile : public QObject
{
    Q_OBJECT
public:
    explicit ConfigFile(const QString& file, QIODevice::OpenMode mode);
    ~ConfigFile();

    bool readRow( const QString&, QRegExp&);
    QString readRow(const QString&);
    bool readRowBool(const QString&);
    bool rowExists(const QString&);
    bool writeRow(const QString&, const QString&);
    bool writeRow(const QString&, double);
    bool writeRow(const QString&, int);
    bool writeRow(const QString&, bool);
    bool writeRow(const QString&, const char*);
    bool getStatus() const;

private:
    QMap<QString,QString> file_contents;
    // Keep track of unread rows
    QTextStream* stream;
    QString filename;
    QIODevice::OpenMode open_mode;
    QFile* device_file;
    bool status;

    QString getRawRow(const QString&);
};

#endif // CONFIGFILE_H
